package com.gexin.model.activity;

import com.gexin.model.activity.base.BaseInviteeRelative;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 业务名称:  t_invitee_relative() 
 */
  @SuppressWarnings("serial")
public class InviteeRelative extends BaseInviteeRelative<InviteeRelative> {
	public static final InviteeRelative dao = new InviteeRelative();

	private List<InviteeRelative> childrenInviteeRelative;

	private BigDecimal topRecommond;

	private String parentId;

	private int branch;

	public int speedIntegral;

	public BigDecimal sum;

	public BigDecimal tobeSum;

	public BigDecimal selfSum;

	public BigDecimal recommond;

	public int level;



	public BigDecimal getTopRecommond() {
		return topRecommond;
	}

	public void setTopRecommond(BigDecimal topRecommond) {
		this.topRecommond = topRecommond;
	}
	public BigDecimal getSelfSum() {
		return selfSum;
	}

	public void setSelfSum(BigDecimal selfSum) {
		this.selfSum = selfSum;
	}

	public BigDecimal getRecommond() {
		return recommond;
	}

	public void setRecommond(BigDecimal recommond) {
		this.recommond = recommond;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public List<InviteeRelative> getChildrenInviteeRelative() {
		return childrenInviteeRelative;
	}

	public void setChildrenInviteeRelative(List<InviteeRelative> childrenInviteeRelative) {
		this.childrenInviteeRelative = childrenInviteeRelative;
	}

	public int getSpeedIntegral() {
		return speedIntegral;
	}

	public void setSpeedIntegral(int speedIntegral) {
		this.speedIntegral = speedIntegral;
	}

	public int getBranch() {
		return branch;
	}

	public void setBranch(int branch) {
		this.branch = branch;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}


	public BigDecimal getTobeSum() {
		return tobeSum;
	}

	public void setTobeSum(BigDecimal tobeSum) {
		this.tobeSum = tobeSum;
	}

	public BigDecimal getSum() {
		return sum;
	}

	public void setSum(BigDecimal sum) {
		this.sum = sum;
	}

	public InviteeRelative getInviteeRelative(String id){
		InviteeRelative inviteeRelative = InviteeRelative.dao.findFirst("select * from t_invitee_relative where user_id="+id);
		return inviteeRelative;
	}


	public InviteeRelative getInviteeRelativeByInteviterId(String inviterId) {
		InviteeRelative inviteeRelativeList = InviteeRelative.dao.findFirst("select * from t_invitee_relative where id="+inviterId);
		return inviteeRelativeList;
	}

	public List<InviteeRelative> getChildrenInviteeList(){
		List<InviteeRelative> inviteeRelativeList = InviteeRelative.dao.findAll();
		return inviteeRelativeList;
	}

	public List<InviteeRelative> findByInviterId(String inviteeRelativeId) {
		List<InviteeRelative> inviteeRelativeList = InviteeRelative.dao.find("select * from t_invitee_relative where inviter_id=" + inviteeRelativeId);
		return inviteeRelativeList;
	}

	public InviteeRelative allInviteeRelative(String id){
		InviteeRelative inviteeRelative=InviteeRelative.dao.findFirst("select * from t_invitee_relative where user_id="+id);
		return inviteeRelative;
	}
	public List<InviteeRelative> allInviteeRelativeList(String id){
		List<InviteeRelative> inviteeRelativeList=InviteeRelative.dao.find("select count(*) from (\n" +
				"              select t1.id,t1.user_id,\n" +
				"              if(FIND_IN_SET(inviter_id,@pids) > 0, @pids := concat(@pids,',', id), 0) as ischild\n" +
				"              from (\n" +
				"                   select id,inviter_id,user_id from t_invitee_relative AS t order by inviter_id, id\n" +
				"                  ) t1,\n" +
				"                  (select @pids :="+id+") t2\n" +
				"             ) t3 where ischild != 0");
		return inviteeRelativeList;
	}

	public InviteeRelative getQueryteam(Integer id){
		InviteeRelative inviteeRelative=InviteeRelative.dao.findFirst("select id,user_id,cretate_time from t_invitee_relative where user_id="+id);
		return inviteeRelative;
	}

	public List<InviteeRelative> getQueryteamList(String id){
		List<InviteeRelative> inviteeRelativeList=InviteeRelative.dao.find("select id,inviter_id,cretate_time,user_id,count(*) as ccc from t_invitee_relative where inviter_id="+id+" GROUP BY id");
		return inviteeRelativeList;
	}

	public List<InviteeRelative> getCount(String id){
		List<InviteeRelative> inviteeRelative=InviteeRelative.dao.find("select count(*) from t_invitee_relative where inviter_id="+id);
		return inviteeRelative;
	}


}
